## Project Euler 67 solver.
## Requires triangle to be flipped via "tac" or some other method first
## This method goes through the next-to-last row, and selects the largest
## of the two possible "paths" on the last row, then adds that number to the
## current entry on the next-to-last row. Then, we delete the last row, and
## repeat the process for the next row. Finally, the very top of the triangle
## will reflect the value of the best possible route. While this only gives us
## the final sum (the answer), I believe it is possible to keep a trace
## of the best route using this method.
triangle = open("fliptriangle.txt")
lastline = []
j = 0
for currline in triangle.readlines():
	j+=1
	currline=currline.split()
	if j==1:
#		print("Line ", j, " Len ", len(currline))
		for i in range(0, len(currline)):
			currline[i] = int(currline[i])
		lastline = currline
	else:
#		print("Line ", j, " Len ", len(currline))
		for i in range(0, len(currline)):
			currline[i] = int(currline[i])
			currline[i] += lastline[i] if lastline[i] > lastline[i+1] else lastline[i+1]
		lastline=currline
		
print(lastline)	